import { createMemoryHistory, createRouter } from 'vue-router'
import Home from "../views/Home.vue";
import Hello from "../views/Hello.vue";
import Haha from "../views/Haha.vue";
import User from "../views/user/User.vue";
import UserProfile from "../views/user/UserProfile.vue";
import UserPosts from "../views/user/UserPosts.vue";



const routes = [
    { path: '/', component: Home },
    { path: '/hello', component: Hello },
    { path: '/haha/:id/:name/:age', component: Haha,name: 'Haha' },
    {
        path: '/user/:id',
        component: User,
        children: [
            {
                // /user/777/profile
                path: 'profile',
                component: UserProfile,
            },
            {
                path: 'posts',
                component: UserPosts
            }
        ]
    }
]

const router = createRouter({
    history: createMemoryHistory(),
    routes: routes
})

router.beforeEach(async (to, from, next) => {
    //await 后端数据
    // 返回false取消导航
    //返回true则导航
    // 返回路径则跳转指定路径
    if(to.path === '/hello'){
        console.log('禁止访问');
        return "/";
    }
})
export default router;